package com.ittest.controller;


import com.ittest.MyDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/books")
public class BookController {


    @Value("${country}")
    //读取yaml数据中的单一数据
    private String country;

    @Value("${user1.name}")
    private String name1;

    @Value("${likes[1]}")
    private String likes1;

    @Value("${users3[1].age}")
    private String age;

    @Value("${tempDir}")
    private String tempDir;

    //使用自动装配，将所有的数据封装到一个Environment中
    @Autowired
    private Environment env;

    @Autowired
    private MyDataSource myDataSource;

    @GetMapping
    public String getById(){
        System.out.println("springboot is running...");
        System.out.println("countyr1+----->"+country);
        System.out.println("name1+----->"+name1);
        System.out.println("likes1+----->"+likes1);
        System.out.println("age+----->"+age);
        System.out.println("tempDir+----->"+tempDir);
        System.out.println(env.getProperty("user1.name"));
        System.out.println(env.getProperty("server.port"));
        System.out.println(myDataSource);
        return "springboot is running...";

    }
}
